package 刷题10月.链表;

import java.util.ArrayList;
import java.util.List;
// https://leetcode-cn.com/problems/palindrome-linked-list/
public class 链表简单234回文链表1005 {

      public class ListNode {
          int val;
          ListNode next;
          ListNode() {}
          ListNode(int val) { this.val = val; }
          ListNode(int val, ListNode next) { this.val = val; this.next = next; }
      }

    class Solution {
        public boolean isPalindrome(ListNode head) {
            List<Integer> list=new ArrayList<Integer>();
            ListNode current=head;
            while(current!=null){
                list.add(current.val);
                current=current.next;
            }
            int front=0;
            int back=list.size()-1;
            while(front<back){
                if(!list.get(front).equals(list.get(back))){
                    return false;
                }
                front++;
                back--;
            }
            return true;
        }
    }
}
